<?php
namespace addons\news\controllers;
use addons\member\models\Member;
use addons\news\models\VoteNewsModel;
use addons\vote\models\VoteLogModel;
use controllers\HomeBase;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use system\Route\Request;

class api extends HomeBase {
	protected $model = '';

	/**
	 * 获取新闻，最新的10条
	 * @author Colin <amcolin@126.com>
	 * @date 2022-02-13 下午8:37
	 */
	public function getNews(){
		$model = new VoteNewsModel();
		$list = $model->limit(0 , 10)->field('id,title')->order('create_time desc')->select();
		return success($list);
	}

	/**
	 * 新闻详情
	 * @param int $id
	 * @author Colin <amcolin@126.com>
	 * @date 2022-02-13 下午6:58
	 * @return string
	 */
	public function detail($id = 0){
		$model = new VoteNewsModel();
		$find = $model->where(['id' => $id])->find();
		if (!$find){
			return error('无效的通知数据');
		}
		$model->where(['id' => $id])->incField('views');
		return success([
			'title' => $find['title'] ,
			'content' => $find['content'] ,
		]);
	}
}